package org.jaaksi.kottlindemo.ui

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import libcore.eventbus2.postEvent
import libcore.eventbus2.registerEvent
import org.jaaksi.kottlindemo.LibConfig
import org.jaaksi.kottlindemo.databinding.ActivitySecondBinding
import org.jaaksi.kottlindemo.home.GlobalEvent

class SecondActivity : AppCompatActivity() {
    private val binding by lazy { ActivitySecondBinding.inflate(layoutInflater) }

//    private val age by argument(20)
//    private val id by argument(key = "ID", defaultValue = 10)
//    private val id2 by argument<Int?>(null)
//    private val id3 by argument(null)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
//
//        println(">> age = $age, id = $id")

        binding.btnPost.setOnClickListener {
//            postEvent(GlobalEvent())
//            lifecycleScope.launch {
//                EventBus.postEvent(GlobalEvent())
//            }
            postEvent(GlobalEvent())
        }

//        registerEvent<GlobalEvent> {
//            Toast.makeText(LibConfig.applicationContext, "收到粘性Event", Toast.LENGTH_SHORT).show()
//        }

//        observeEvent<GlobalEvent>(isSticky = true) {
//            Toast.makeText(LibConfig.applicationContext, "收到粘性Event", Toast.LENGTH_SHORT).show()
//        }
    }
}